#!/bin/bash

# 启动一个新的 tmux 会话，命名为 "run_multi_fixedwing_sitl"
tmux new-session -d -s multi_fixedwing

# 运行fixedwing_3.launch,生成plane3
tmux send-keys -t multi_fixedwing "roslaunch fixedwing_sitl fixedwing_3.launch" C-m
sleep 8

# 创建新的窗格并运行move_plane3.py，移动刚刚生成的飞机
tmux split-window -v -t multi_fixedwing
tmux send-keys -t multi_fixedwing "rosrun fixedwing_sitl move_plane3.py; exit" C-m
sleep 2

# 运行fixedwing_2.launch,生成plane2
tmux split-window -h -t multi_fixedwing
tmux send-keys -t multi_fixedwing "roslaunch fixedwing_sitl fixedwing_2.launch" C-m
sleep 8

# 创建新的窗格并运行move_plane2.py，移动刚刚生成的飞机
tmux split-window -v -t multi_fixedwing
tmux send-keys -t multi_fixedwing "rosrun fixedwing_sitl move_plane2.py; exit" C-m
sleep 2

# 运行fixedwing_1.launch,生成plane1
tmux split-window -h -t multi_fixedwing
tmux send-keys -t multi_fixedwing "roslaunch fixedwing_sitl fixedwing_1.launch" C-m
sleep 2

# 创建新的窗格并运行pack_follower1_states.py
tmux split-window -h -t multi_fixedwing
tmux send-keys -t multi_fixedwing "rosrun fixedwing_sitl pack_follower1_states.py" C-m
sleep 3

# 创建新的窗格并运行pack_follower2_states.py
tmux split-window -h -t multi_fixedwing
tmux send-keys -t multi_fixedwing "rosrun fixedwing_sitl pack_follower2_states.py" C-m
sleep 3

# 创建新的窗格并运行pack_follower3_states.py
tmux split-window -h -t multi_fixedwing
tmux send-keys -t multi_fixedwing "rosrun fixedwing_sitl pack_follower3_states.py" C-m
sleep 3

# 创建新的窗格并运行领机的pos_offb.py
tmux split-window -v -t multi_fixedwing
# tmux send-keys -t multi_fixedwing "rosrun fixedwing_sitl pos_control_offb.py" C-m
tmux send-keys -t multi_fixedwing "rosrun fixedwing_sitl formation_path_control_offb.py" C-m
sleep 2

# # 创建新的窗格并运行从机的att_offb.py
# tmux split-window -v -t multi_fixedwing
# tmux send-keys -t multi_fixedwing "rosrun fixedwing_sitl att_control_offb.py" C-m
# sleep 2

# # 创建新的窗格并运行switch_follower1_mode.py
# tmux split-window -v -t multi_fixedwing
# tmux send-keys -t multi_fixedwing "rosrun fixedwing_sitl switch_follower1_mode.py" C-m
# sleep 5

# # 创建新的窗格并运行switch_follower2_mode.py
# tmux split-window -v -t multi_fixedwing
# tmux send-keys -t multi_fixedwing "rosrun fixedwing_sitl switch_follower2_mode.py" C-m
# sleep 5

# # 创建新的窗格并运行switch_follower3_mode.py
# tmux split-window -v -t multi_fixedwing
# tmux send-keys -t multi_fixedwing "rosrun fixedwing_sitl switch_follower3_mode.py" C-m
# sleep 5

# 创建新的窗格并运行formation_switch_mode.py
tmux split-window -v -t multi_fixedwing
tmux send-keys -t multi_fixedwing "rosrun fixedwing_sitl formation_switch_mode.py" C-m

# 如果还有其他的 Python 程序，可以继续添加新的窗格
# tmux split-window -h -t my_session
# tmux send-keys -t my_session "python3 /path/to/your/fourth_script.py" C-m

# 选择窗口布局，例如 tiled 布局
tmux select-layout -t multi_fixedwing tiled

# 让 tmux 会话附加到当前终端
tmux attach-session -t multi_fixedwing